package com.onlocation.util;

import java.text.DecimalFormat;

/**
 * Author: Steve Carrell
 * Date: 5/10/12
 */
public class StringUtil {
    public static boolean isNullOrEmpty(String s) {
        return s == null || s.equals("");
    }

    public static boolean equalsIgnoreNull(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        } else {
            return s1.equals(s2);
        }
    }

    public static String formatDecimalString(double d, int sig) {
        String s;
        try {
            if (sig < 0) {
                s = String.valueOf(d);
            } else {
                String format = "#0.0";
                for (int i = 1; i < sig; i++) {
                    format += "#";
                }
                s = new DecimalFormat(format).format(d);
            }
        } catch (Exception e) {
            s = "0.0";
        }
        
        return s;
    }
}
